package com.aaron.book.thinkinginjava.c21.p654;

/**
 * @author liurong
 * @date 2021/7/8 10:56
 */
public class LiftOff implements Runnable {

    protected int countDown = 10;

    private static int taskCount = 0;

    //final 一旦初始化后就不会被修改
    private final int id = taskCount++;//taskCount为static变量，对象共享，每new新的LiftOff对象会初始化id，然后taskCount会+1

    public LiftOff(){};

    public LiftOff(int countDown) {
        this.countDown = countDown;
    }

    public String status(){
        return "#" + id + "(" + (countDown > 0 ? countDown : "LiftOff!") + "), ";
    }

    @Override
    public void run() {
        while (countDown-- > 0) {
            System.out.println(status());
            Thread.yield();
        }
    }

    public int getId() {
        return this.id;
    }
}
